# title: 异质性随机前沿模型I——真实固定效应
# author: StableGenius
# date: 2020-01-20
# description: 知乎专栏-科研斗牛犬源代码

# clear workspace
rm(list = ls())

# set work directory
setwd(dirname(parent.frame(2)$ofile))

# load user-defined script
source("core_maxlik.R")

# load dataset and trans to panel data
data("riceProdPhil")
riceProdPhil <- riceProdPhil %>%
  pdata.frame(index = c("FMERCODE", "YEARDUM"))

# specify model
model <- log(PROD) ~ log(AREA) + log(LABOR) + log(NPK)

# classical sfa model
print(summary(frontier::sfa(model, riceProdPhil)))

# "true" fixed-effect stochastic frontier model
huaji <- sfa_tfe(formula = model, data = riceProdPhil)
print(summary(huaji))